package com.rms.hr.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.rms.hr.dao.UserMapper;
import com.rms.hr.model.User;
import com.rms.hr.service.UserService;

/**
 * @author lgw0822
 * 
 */
@Service("userService")
public class UserServiceImpl implements UserService {

	public UserMapper userMapper;

	@Autowired
	public void setUserMapper(UserMapper userMapper) {
		this.userMapper = userMapper;
	}

	/**
	 * @return
	 */
	public List<User> getAllUser() {
		List<User> userList = this.userMapper.selectAll();
		return userList;
	}

	@Override
	public int creatUser(User user) {
		return this.userMapper.insert(user);
	}

	@Override
	public User selectByPrimaryKey(Integer id) {
		return this.userMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateUser(User user) {
		return this.userMapper.updateByPrimaryKey(user);
	}

	@Override
	public void deleteUserById(Integer id) {
		this.userMapper.deleteByPrimaryKey(id);
	}

	/**
	 * 管理员登录
	 * 
	 * @return
	 */
	@Override
	public User findUserForLogin(User user) {
		List<User> users = this.userMapper.findUserForLogin(user);
		return users.size()>0?users.get(0):null;
	}
}
